package com.cloudree.gllib.render.cylinder;

import android.opengl.GLES20;
import android.opengl.Matrix;

import com.cloudree.gllib.render.BaseRender;
import com.cloudree.gllib.shape.Circle;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

/**
 * Created by Administrator on 2017/10/10 0010.
 */
public class CircleRender extends BaseRender {
    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        GLES20.glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
        mShape = new Circle();

    }

    @Override
    public void onSurfaceChanged(GL10 gl, int width, int height) {
        float ratio = width > height ? (float) width / (float) height : (float) height / (float) width;
        if (width>height){//landscape
            Matrix.orthoM(mProjectionMatrix,0,-ratio,ratio,-1,1,-1,1);
        }else {//portrait
            Matrix.orthoM(mProjectionMatrix,0,-1,1,-ratio,ratio,-1,1);
        }
        GLES20.glViewport(0, 0, width, height);
//         GLES20.glViewport(0,0,width,width);
    }

    @Override
    public void onDrawFrame(GL10 gl) {
//        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
        GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
        mShape.draw(mMVPMatrix, mModelMatrix, mViewMatrix, mProjectionMatrix);
    }
}
